package org.example.myleet.p1614;

public class Solution {

    public int maxDepth(String s) {
        int maxDept = 0;
        int n = s.length();
        int stackSize = 0;
        char[] charArr = s.toCharArray();
        for (int i = 0; i < n; ++i) {
            char c = charArr[i];
            if (c == '(') {
                stackSize++;
            } else if (c == ')') {
                if (stackSize > 0) {
                    maxDept = Math.max(maxDept, stackSize);
                    --stackSize;
                }
            }
        }
        return maxDept;
    }
}
